﻿using Jinjia.Core.Attribute;
using JinJia.Core.MQProvider;
using Jinjia.Approve.IRepository;
using Jinjia.Approve.IService;
using Jinjia.Approve.Model.Input;
using Jinjia.Approve.Model.VM;
using Jinjia.Approve.Service.Base;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Jinjia.Core.BaseInfrastructure.StorageModel;
using Jinjia.Approve.Entity.Entity;

namespace Jinjia.Approve.Service
{
    public class HelloWorldService : BaseService, IHelloWorldService
    {
        #region 方式一: 直接注入仓储模型接口(若无复杂业务,推荐当前方式)

        private readonly IBaseRepository<hello_world_tbl> _baseRepository;

        #endregion

        #region 方式二: 通过自定义仓储接口, 接口实现继承仓储实现或注入仓储模型接口(复杂业务自定义可用)

        private readonly IHelloWorldRepository _helloWorldRepository;

        #endregion

        private readonly IRabbitMQProvider rabbitMQProvider;

        public HelloWorldService(IHelloWorldRepository helloWorldRepository,
            IRabbitMQProvider rabbitMQProvider,
            IBaseRepository<hello_world_tbl> baseRepository)
        {
            _helloWorldRepository = helloWorldRepository;
            this.rabbitMQProvider = rabbitMQProvider;
            _baseRepository = baseRepository;
        }

        public void SendMsg<T>(T msg)
        {
            var rabbitMQService = rabbitMQProvider.GetRabbitMQService("请输入客户端名");
            rabbitMQService.Send("请输入交换机名", "请输入路由键名", JsonConvert.SerializeObject(msg));
        }

        public async Task<HelloWorldVM> InsertMysqlHelloWorld(HelloWorldCreateInput input)
        {
            return await _helloWorldRepository.InsertMysqlHelloWorld(input);
        }

        [UseTran]
        public virtual async Task<HelloWorldVM> ReadMysqlHelloWorld(HelloWorldSearchInput input)
        {
            return await _helloWorldRepository.ReadMysqlHelloWorld(input);
        }
    }
}